home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / reduce_colors.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  67 lines

  1. ; $Id: reduce_colors.pro,v 1.5 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1992-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. PRO REDUCE_COLORS, Image, Values
  7. ;+
  8. ; NAME:
  9. ;    REDUCE_COLORS
  10. ;
  11. ; PURPOSE:
  12. ;    This procedure reduces the number of colors used in an image
  13. ;    by eliminating pixel values without members.
  14. ;
  15. ; CATEGORY:
  16. ;    Image display.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    REDUCE_COLORS, Image, Values
  20. ;
  21. ; INPUTS:
  22. ;    Image:  The original image array. Note that the input array is
  23. ;        replaced by its color-reduced equivalent.
  24. ;
  25. ; KEYWORD PARAMETERS:
  26. ;    None.
  27. ;
  28. ; OUTPUTS:
  29. ;    Image:  The color-reduced image array.
  30. ;    Values: A vector of non-zero pixel values. If Image contains
  31. ;        pixel values from 0 to M, Values will be an M+1 element
  32. ;        vector containing the mapping from the old values to
  33. ;        the new. Values[I] contains the new color index of old
  34. ;        pixel index I.
  35. ;
  36. ; SIDE EFFECTS:
  37. ;    Input array is overwritten.
  38. ;
  39. ; PROCEDURE:
  40. ;    The pixel distribution histogram is obtained and the WHERE
  41. ;    function is used to find bins with non-zero values. Next,
  42. ;    a lookup table is made where table[old_pixel_value] contains
  43. ;    new_pixel_value, and then applied to the image.
  44. ;        
  45. ; EXAMPLE:
  46. ;    To reduce the number of colors and display an image with the
  47. ;    original color tables R, G, B:
  48. ;      REDUCE_COLORS, Image, V
  49. ;      TVLCT, R[V], G[V], B[V]
  50. ;
  51. ; MODIFICATION HISTORY:
  52. ;    DMS,    RSI, Oct, 1992.
  53. ;-
  54.  
  55. h = histogram(image, omax = mx, min = 0) ;Find distribution
  56. Values = where(h)            ;Non-zero elements
  57.     ;Make translation table using lowest possible precision
  58. if mx le 255 then table = bytarr(mx+1) $
  59. else if mx le 32767 then table = intarr(mx+1L) $
  60. else table = lonarr(mx+1L)
  61.  
  62. table[values] = lindgen(n_elements(values))    ;Fill the table
  63.  
  64.     ;Translate to reduced palette
  65. image = table[temporary(image)]
  66. end
  67.